var app = new Vue({
	el: '#idx',
	data() {
		return {
			formInline: {
				name: '',
				sno: '',
				phone: ''
			},
			ruleInline: {
				name: [{
						required: true,
						message: '请填写姓名',
						trigger: 'blur'
					},
					{
						type: 'string',
						min: 2,
						max: 10,
						message: '姓名长度不能小于2位',
						trigger: 'blur'
					}
				],
				sno: [{
						required: true,
						message: '请填写学号',
						trigger: 'blur'
					},
					{
						type: 'string',
						min: 6,
						max: 20,
						message: '学号长度不能小于6位',
						trigger: 'blur'
					}
				],
				phone: [{
						required: true,
						message: '请填写联系电话',
						trigger: 'blur'
					},
					{
						type: 'string',
						min: 11,
						max: 11,
						message: '电话长度11位',
						trigger: 'blur'
					}
				]
			}
		}
	},
	methods: {
		handleSubmit(name) {
			var that = this
			that.$refs[name].validate((valid) => {
				if (valid) {
					axios.post('/students', {
							name: that.formInline.name,
							sno: that.formInline.sno,
							phone: that.formInline.phone
						})
						.then(function(response) {
							if (response.data == "ok") {
								window.location.href = "/exam";
							}else if(response.data.indexOf("error?")==0){
								window.location.href=response.data;
							}
						})
						.catch(function(error) {
							that.$message.error('保存学生信息失败!');
						});

				} else {
					that.$message.error('表单验证失败!');
				}
			})
		}
	}
})


